home *** CD-ROM | disk | FTP | other *** search
/ SPACE 1 / SPACE - Library 1 - Volume 1.iso / program / 356 / clipmod / showclip.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-02-02  |  6.0 KB  |  184 lines

  1. /****************************************************************************\
  2. |*        SHOWCLIP.ACC                                                        *|
  3. |*--------------------------------------------------------------------------*|
  4. |*    by Russ Wetmore                                                            *|
  5. |*        Last revision:    11/04/86 15:02:20                                    *|
  6. \****************************************************************************/
  7. /*------------------------------*\
  8. |*    includes                    *|
  9. \*------------------------------*/
  10. #include <define.h>
  11. #include <gem.h>                        /* GEMDEFS.H & OBDEFS.H                */
  12. #include <tos.h>                        /* TOSDEFS.H & OSBIND.H                */
  13. #include <string.h>                        /* for string copies
  14.  
  15. #define MEGAMAX                            /* We're using Megamax C            */
  16. #include "clip.h"                        /* Clipboard equates & portability    */
  17.  
  18. /*------------------------------*\
  19. |*    local defines                *|
  20. \*------------------------------*/
  21. #define STRSIZE 25                        /* Max string length in alert        */
  22. #define STRTOTAL (5*STRSIZE)            /* Whole alert is five lines long    */
  23. #define RASPBERRY() Bconout(2,7)        /* Shortcut                            */
  24.  
  25. /*------------------------------*\
  26. |*    imports                        *|
  27. \*------------------------------*/
  28. IMPORT    WORD    gl_apid;                /* To fix someone else's bug        */
  29.  
  30. /*------------------------------*\
  31. |*    exports                        *|
  32. \*------------------------------*/
  33. GLOBAL    WORD    contrl[12],                /* Idiotic GEM bindings                */
  34.                 intin[128],
  35.                 ptsin[128],
  36.                 intout[128],
  37.                 ptsout[128];
  38.  
  39. /*------------------------------*\
  40. |*    locals                        *|
  41. \*------------------------------*/
  42. LOCAL    BYTE    NODATA[] = "[1][ |Nothing in clipboard| ][ OK ]",
  43.                 yesstr[] = "Yes",
  44.                 nostr[] = "No",
  45.                 dunnostr[] = "On CLIP.SYS",
  46.                 inmemstr[] = "In memory",
  47.                 NoClipTrap[] = "[3][Clipboard TRAP routines are not|installed. Be sure the CLIP.PRG|file is in the \\AUTO folder on|your boot disk.][ OK ]",
  48.                 FileNotFound[] = "[1][ |No clipboard file on disk| ][ OK ]",
  49.                 ReadError[] = "[3][ |Some kind of read error!| ][ OK ]";
  50.  
  51.  
  52. /*------------------------------*\
  53. |*    HandleError                    *|
  54. \*------------------------------*/
  55.     LOCAL
  56.     VOID
  57. HandleError(err)
  58.     WORD err;
  59. {
  60.     BYTE tempstr[256], *alertstr = tempstr;
  61.  
  62.     switch (err) {
  63.         case EFILNF:
  64.             alertstr = FileNotFound;
  65.             break;
  66.         case EREADF:
  67.             alertstr = ReadError;
  68.             break;
  69.         default:
  70.             sprintf(tempstr, "[3][ |Unknown error: %d| ][ OK ]", err);
  71.             break;
  72.     }
  73.     RASPBERRY();
  74.     form_alert(1, alertstr);
  75. }
  76.  
  77. /*------------------------------*\
  78. |*    DoInformation                *|
  79. \*------------------------------*/
  80.     LOCAL
  81.     VOID
  82. DoInformation(infoPtr)
  83.     clipInfo *infoPtr;
  84. {
  85.     BYTE alertstr[256];
  86.  
  87.     sprintf(alertstr,
  88.       "[1][Size: %ld|Loc: %lx|Dirty: %s|Where: %s|Fname: %s][ OK ]",
  89.       infoPtr->size, infoPtr->location,
  90.       infoPtr->dirty ? yesstr : nostr,
  91.       infoPtr->where ? inmemstr : dunnostr,
  92.       infoPtr->filename);
  93.  
  94.     form_alert(1, alertstr);
  95. }
  96.  
  97. /*------------------------------*\
  98. |*    main                        *|
  99. \*------------------------------*/
  100.     GLOBAL
  101.     WORD
  102. main()
  103. {
  104.     BYTE *dataPtr, alertstr[256], lines[5][STRSIZE+1];
  105.     WORD msgbuff[8];
  106.     WORD myMenu, i, j;
  107.     LONG length;
  108.     clipInfo *infoPtr;
  109.  
  110.     /*----------------------------------------------------------------------*\
  111.     |*    We're a GEM application.  Register at front desk.                    *|
  112.     \*----------------------------------------------------------------------*/
  113.     appl_init();
  114.     myMenu = menu_register(gl_apid, "  Show clipboard");
  115.  
  116.     for (;;) {
  117.         /*------------------------------------------------------------------*\
  118.         |*    Ask AES what's up and respond if Butch is opening us up            *|
  119.         \*------------------------------------------------------------------*/
  120.         evnt_mesag(msgbuff);
  121.         if ( msgbuff[0] == AC_OPEN && msgbuff[4] == myMenu ) {
  122.  
  123.             /*--------------------------------------------------------------*\
  124.             |*    First, we check to see if the clipboard is around            *|
  125.             \*--------------------------------------------------------------*/
  126.             if ( !InfoClip(&infoPtr) ) {    /* FALSE result means no clip    */
  127.                 RASPBERRY();
  128.                 form_alert(1, NoClipTrap);
  129.                 continue;
  130.             }
  131.  
  132.             /*--------------------------------------------------------------*\
  133.             |*    It is, so show information about it                            *|
  134.             \*--------------------------------------------------------------*/
  135.             DoInformation(infoPtr);
  136.  
  137.             /*--------------------------------------------------------------*\
  138.             |*    Bring clipboard into memory                                    *|
  139.             \*--------------------------------------------------------------*/
  140.             i = GetClip(&dataPtr, &length, TRUE);
  141.             if ( i < 0 ) {                    /* Negative result means error!    */
  142.                 HandleError(i);
  143.                 continue;
  144.             }
  145.  
  146.             /*--------------------------------------------------------------*\
  147.             |*    Inform Butch of special case of clipboard but no contents    *|
  148.             \*--------------------------------------------------------------*/
  149.             if ( !length ) {                /* Nothing there                */
  150.                 form_alert(1, NODATA);
  151.                 continue;
  152.             }
  153.  
  154.             /*--------------------------------------------------------------*\
  155.             |*    For purposes of this demo, truncate string to fit alert        *|
  156.             \*--------------------------------------------------------------*/
  157.             if ( length > STRTOTAL )
  158.                 dataPtr[STRTOTAL] = '\0';
  159.  
  160.             /*--------------------------------------------------------------*\
  161.             |*    Initialize strings and fill them a line at a time            *|
  162.             \*--------------------------------------------------------------*/
  163.             for (j=0; j<5; ++j)
  164.                 *lines[j] = lines[j][STRSIZE] = '\0';
  165.  
  166.             for (j=0; length>0 && j<5; ++j, length-=STRSIZE)
  167.                 strncpy(lines[j], dataPtr + j * STRSIZE, STRSIZE);
  168.  
  169.             /*--------------------------------------------------------------*\
  170.             |*    Cheap way of creating alert string                            *|
  171.             \*--------------------------------------------------------------*/
  172.             sprintf(alertstr,
  173.               "[1][>%-25s<|>%-25s<|>%-25s<|>%-25s<|>%-25s<][OK| Flush clip ]",
  174.               lines[0], lines[1], lines[2], lines[3], lines[4]);
  175.  
  176.             /*--------------------------------------------------------------*\
  177.             |*    If Butch tells us to flush, then flush                        *|
  178.             \*--------------------------------------------------------------*/
  179.             if ( form_alert(1, alertstr) == 2 )
  180.                 ZeroClip();
  181.         }
  182.     }
  183. }
  184.